package com.gxc.utils;

import java.lang.reflect.UndeclaredThrowableException;

/** 获取Throwable里头的错误信息. */
public class ThrowableMessageUtil {

  /** 获取 Throwable 的错误信息. */
  public static String getMessage(Throwable e) {
    String msg = null;
    if (e instanceof UndeclaredThrowableException) {
      Throwable targetEx = ((UndeclaredThrowableException) e).getUndeclaredThrowable();
      if (targetEx != null) {
        msg = targetEx.getMessage();
      }
    } else {
      msg = e.getMessage();
    }
    return msg;
  }
}
